// index.ts
import { formatTime } from "../../utils/util"

// 获取应用实例
Page({
  data: {
    image: "",
    now: ""
  },
  // 事件处理函数
  cameraErr(event: any) {
    wx.showToast({
      title: "相机不可用" + event
    })
  },
  getDateStr() {
    return formatTime(new Date())
  },
  captcher() {
    wx.showToast({
      title:"开始拍照"
    })
    let ctx = wx.createCameraContext()
    ctx.takePhoto({
      quality: "high",
      success: (res) => {
        console.log(res.tempImagePath)
        this.setData({
          image: res.tempImagePath
        })
       
        wx.navigateTo({
          url: "/pages/preview/preview?src=" + res.tempImagePath
        })
      },
      fail(err) {
        console.log(err)
      }
    }); 
  },
  onLoad() {
    // @ts-ignore
    setInterval(() => {
      let current = this.getDateStr()
      this.setData({
        now: current
      })
    }, 1000)
  },
  onUnload() {
    
  }
  
})
